﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using System.Data;

namespace DataAccess
{
    public partial class MySQLDataAccess :IDataAccess
    {


        #region IDataAccess Members


        public List<string> GetViewList(ConnectionInformation connectionInformation)
        {
            QueryStringBuilder = new StringBuilder();
            QueryStringBuilder.Append("select Table_Name from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='");
            QueryStringBuilder.Append(connectionInformation.DataBaseName);
            QueryStringBuilder.Append("' And Table_Type='VIEW'");

            return GenerateTableList(ExecuteQuery(connectionInformation, QueryStringBuilder.ToString()),1, 0);
        }
        /// <summary>
        /// Get Information of a View and return TableInformation Object.
        /// But it will retrieve only sample data in dataTable(DataTable).
        /// For getting full data call GetFullData(ConnectionInformation connectionInformation, string tableName/ViewName,out TableInforamation tableInformation) after calling this function.
        /// </summary>
        /// <param name="connectionInformation"></param>
        /// <param name="VableName"></param>
        /// <returns></returns>
        public TableInformation GetViewInformation(ConnectionInformation connectionInformation, string ViewName)
        {
            TableInformation tableInformation = new TableInformation();
            string QueryString = "Select * from " + ViewName + " Limit 10";

            tableInformation.DataTable = ExecuteQuery(connectionInformation, QueryString);

            List<Column> Columnlist = GenerateColumnInformation(connectionInformation, ViewName, QueryString);

            tableInformation.ColumnList = Columnlist;

            tableInformation.DataTable.TableName = ViewName;

            return tableInformation;
        }

       #endregion
    }
}
